package com.wyp168.leetcode;

/**
 * @ClassName GetKthMagicNumber
 * @Description TODO
 * @Author wyp168
 * @Date 2022/9/28 21:38
 */
public class GetKthMagicNumberSolution {
    public static void main(String[] args) {
        GetKthMagicNumberSolution getKthMagicNumberSolution = new GetKthMagicNumberSolution();
        System.out.println(getKthMagicNumberSolution.getKthMagicNumber(5));
    }

    public int getKthMagicNumber(int k) {
        long[] queue = new long[k + 1];
        int n3 = 0, n5 = 0, n7 = 0;
        //初始化queue
        queue[0] = 1;
        for (int i = 1; i < k; i++) {
            queue[i] = Math.min(Math.min(queue[n3] * 3, queue[n5] * 5), queue[n7] * 7);

            if (queue[n3] * 3 == queue[i]) n3 ++;
            if (queue[n5] * 5 == queue[i]) n5 ++;
            if (queue[n7] * 7 == queue[i]) n7 ++;
        }
        return (int)queue[k - 1];
    }
}
